﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TraceThisItem.Domain;

namespace TraceThisItem.WebUI.ItemTypes
{
    public partial class Create : System.Web.UI.Page
    {
		private string ProjectId;
      
        protected void Page_Load(object sender, EventArgs e)
        {
			if (Request.QueryString["projectId"] != null)
			{

				this.ProjectId = Request.QueryString["projectId"];
				lblProyectoAsociado.Text = "Proyecto: "+ Facade.Instance.GetProjectNameById(Convert.ToInt32(this.ProjectId));
			}
        }

        protected void ProjectDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = Facade.Instance;
        }

        protected void btnAgregarTipoDeItem_Click(object sender, EventArgs e)
        {
			if (Page.IsValid)
			{

				ItemType newItemType = new ItemType();

				newItemType.Name = txtNombreTipoDeItem.Text;
				newItemType.ProjectId = Convert.ToInt32(this.ProjectId);
				newItemType.WorkflowId = Convert.ToInt32(ddlWorkFlows.SelectedValue);

				Facade.Instance.AddItemType(newItemType);
				Response.Redirect("~/ItemTypes/Default.aspx?projectId=" + this.ProjectId);
			}
        }

        protected void ProjectDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["userName"] = User.Identity.Name;
        }

        protected void WorkFlowsDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = Facade.Instance;
        }

    }
}